package com.coolzeng.controller;

import com.coolzeng.entity.JsonResult;
import com.coolzeng.entity.Reply;
import com.coolzeng.service.ReplyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * Created by Administrator on 2017/6/11.
 */
@Controller
public class ReplyController {

    @Autowired
    private ReplyService replyService;
//根据帖子id获取回复
    @RequestMapping("/reply/{postId}")
    @ResponseBody
    public JsonResult reply(@PathVariable("postId")int id){
        List<Reply> replies=replyService.getReplysByPostId(id);
        JsonResult jsonResult=new JsonResult(replies,"this is message",true);
        return jsonResult;
    }

    @RequestMapping("/reply/addreply")
    @ResponseBody
    public void addreply(@RequestBody Reply reply){
        /*获取当前时间*/
        Date date=new Date();
        DateFormat format=new SimpleDateFormat("yyyy-MM-dd HH:mm");
        String time=format.format(date);

        Reply newreply=new Reply();
        newreply.setReplycontent(reply.getReplycontent());
        newreply.setReplypostid(reply.getReplypostid());
        newreply.setReplyuserid(reply.getReplyuserid());
        newreply.setReplyusername(reply.getReplyusername());
        newreply.setReplytime(time);

        newreply.setReplyfatherid(reply.getReplyfatherid());
        newreply.setReplyfloor(reply.getReplyfloor());

        replyService.addReply(newreply);


    }



}
